# $Id: GNUmakefile,v 1.4 2011/01/15 06:42:36 pgurumur Exp $
# Copyright (c) 2009 Prabhu Gurumurthy  <pgurumur@gmail.com>
# 
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

# version "$Revision: 1.4 $"
# author "$Author: pgurumur $"

PROG := dictc
UNAME	:= $(shell uname)
CC := gcc
OBJS	:= $(patsubst %.c,%.o,$(wildcard *.c))
CFLAGS	+= -O2 -W -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes
CFLAGS	+= -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual
CFLAGS	+= -Wsign-compare -fPIC -I.
BFLAGS	:= -fPIC
LDFLAGS	:=

ifeq ($(UNAME), OpenBSD)
CFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib
endif

ifeq ($(UNAME), Linux)
CFLAGS += -D_XOPEN_SOURCE -D_BSD_SOURCE
endif

ifeq ($(UNAME), Darwin)
CFLAGS += -I/opt/local/include
LDFLAGS += -L/opt/local/lib
endif

ifeq ($(CC), icc)
CFLAGS	+= -fPIE -axSSE4.2 -march=core-avx-i 
BFLAGS	+= -fPIE
endif

LDFLAGS += -ledit -lutil
RM := /bin/rm -f

all : $(PROG)

$(PROG) : $(OBJS)
	@echo "building $@, using $(CC)"
	@${CC} $(BFLAGS) -o $@ $^ ${LDFLAGS}

%.o: %.c
	@echo "compiling $<"
	@${CC} ${CFLAGS} -c -o $@ $<

clean:
	@echo "cleaning... ${PROG} ${OBJS}"
	@${RM} ${PROG} ${OBJS}
